package com.cqut.forum.service.imp;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.cqut.forum.dao.ArticleGroupDao;
import com.cqut.forum.entity.ArticleGroup;
import com.cqut.forum.service.ArticleGroupService;
import com.cqut.forum.util.MapKey;

/**
 * aritcleGroupService 实现类
 * @author yangxun
 */
@Controller
public class ArticleGroupServiceImp implements ArticleGroupService {

	@Resource
	private ArticleGroupDao articleGroupDao;
	@Override
	public ArticleGroup getArticleGroup(String groupName) {
		ArticleGroup articleGroup = articleGroupDao.getByName(groupName);
		return articleGroup;
	}

	@Override
	public ArticleGroup updateArticleGroup(ArticleGroup articleGroup) {
		articleGroup = articleGroupDao.update(articleGroup);
		
		return articleGroup;
	}

	@Override
	public List<ArticleGroup> getByOwnerId(int userId,int index,int size) {
		List<ArticleGroup> groups = articleGroupDao.getGroups(userId,index,size);
		return groups;
	}

	@Override
	public ArticleGroup addArticleGroup(ArticleGroup articleGroup) {
		articleGroup = articleGroupDao.save(articleGroup);
		return articleGroup;
	}

	@Override
	public ArticleGroup getGroupById(int groupId) {
		ArticleGroup ar = articleGroupDao.get(groupId, ArticleGroup.class);
		return ar;
	}

	@Override
	public ArticleGroup deleteById(int groupId) {
		ArticleGroup ar = articleGroupDao.delete(groupId, ArticleGroup.class);
		return ar;
	}

	@Override
	public List<Map<String, Object>> loadGardenGroup() {
		List<Map<String, Object>> groups = articleGroupDao.loadGroupsByModuleName("花园");
		
		return MapKey.changeMapKey(groups);
	}
}
